import {
  IConstant_Enum_Type_UserClient_Status,
  Constant_Enum_Enum_UserClient_Status,
  Constant_Enum_Name_UserClient_Type,
  Constant_Enum_Enum_UserClient_Type,
  IConstant_Enum_Type_UserClient_Type,
} from '@/common/constants/enum';
import { ApiProperty } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import { Column, CreateDateColumn, Entity, OneToMany, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { CouponUserClient } from '../../couponUserClient/assets/couponUserClient.entity';
import { InviteRelation } from '../../inviteRelation/assets/inviteRelation.entity';
import { Rebates } from '../../rebates/assets/rebates.entity';

@Entity('userclient')
export class UserClient {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  @ApiProperty({ description: '用户名' })
  userName: string;

  @Column({ nullable: true, type: 'bigint' })
  @ApiProperty({ type: 'bigint', description: '手机号' })
  phone?: number;

  @Column({ nullable: true })
  @ApiProperty({ description: '邮箱' })
  email?: string;

  @Column({ nullable: true, default: Constant_Enum_Enum_UserClient_Status.UserClient_Status_Enable })
  @Exclude()
  @ApiProperty({
    default: Constant_Enum_Enum_UserClient_Status.UserClient_Status_Enable,
    description: '状态',
    enum: Constant_Enum_Enum_UserClient_Status,
  })
  statusUser: IConstant_Enum_Type_UserClient_Status;

  @Column({ nullable: true })
  @Exclude()
  @ApiProperty({ description: '密码' })
  password?: string;

  @Column({ nullable: true })
  @Exclude()
  @ApiProperty({ description: '微信openid' })
  openid?: string;

  @Column({ nullable: true })
  @Exclude()
  @ApiProperty({ description: '头像' })
  headimgurl?: string;

  @ApiProperty({ description: '优惠券领取情况', type: () => CouponUserClient })
  @OneToMany(() => CouponUserClient, (couponUserClient) => couponUserClient.userClient)
  userClient?: CouponUserClient[];

  @OneToOne(() => InviteRelation, (inviteRelation) => inviteRelation.inviter) // 将另一面指定为第二个参数
  inviteRelation?: InviteRelation;

  @OneToMany(() => InviteRelation, (inviteRelation) => inviteRelation.invitee) // 将另一面指定为第二个参数
  invitees?: InviteRelation[];

  @Column({ nullable: true })
  @Exclude()
  @ApiProperty({ description: '分销码' })
  distributionCode?: string;

  @CreateDateColumn({
    type: 'datetime',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP(0)',
    onUpdate: 'CURRENT_TIMESTAMP(0)',
  })
  createTime?: Date;

  @Column({ nullable: true, default: Constant_Enum_Enum_UserClient_Type.UserClient_Type_Normal })
  @ApiProperty({
    default: Constant_Enum_Enum_UserClient_Type.UserClient_Type_Normal,
    enum: Constant_Enum_Enum_UserClient_Type,
    description: '推广者类型' + Constant_Enum_Name_UserClient_Type,
  })
  distributionType?: IConstant_Enum_Type_UserClient_Type;

  @OneToOne(() => Rebates, (rebates) => rebates.inviter)
  @ApiProperty({ description: '邀请者', type: () => Rebates })
  rebatesInviter?: Rebates;

  @OneToOne(() => Rebates, (rebates) => rebates.invitee)
  @ApiProperty({ description: '被邀请者', type: () => Rebates })
  rebatesInvitee?: Rebates;

  @OneToOne(() => InviteRelation, (rebates) => rebates.inviter)
  @ApiProperty({ description: '邀请者', type: () => InviteRelation })
  inviteRelationInviter?: InviteRelation;

  @OneToOne(() => InviteRelation, (rebates) => rebates.invitee)
  @ApiProperty({ description: '被邀请者', type: () => InviteRelation })
  inviteRelationInvitee?: InviteRelation;
}
